const Router = require('koa-router');
const GradeRouter = new Router();
const GradeService = require('../service/GradeService');
const R = require('../utils/R');
const Validators = require('../utils/validators');

GradeRouter.prefix('/api/v1/grade');

GradeRouter.post('/save', async (ctx, next) => {
    let obj = ctx.request.body;
    Validators.isNull(obj.courseId, 'courseId').isNull(obj.studentId, 'studentId').isNull(obj.grade, 'grade');
    await GradeService.saveGrade(obj);

    ctx.body = R.okMsg('添加成功');
})

GradeRouter.post('/update', async (ctx, next) => {
    let obj = ctx.request.body;
    Validators.isNull(obj.courseId, 'courseId').isNull(obj.studentId, 'studentId').isNull(obj.grade, 'grade');
    await GradeService.updateGade(obj);
    ctx.body = R.okMsg('修改成功')
})

module.exports = GradeRouter